import { queryRoleList, queryHomeCount } from '@/services/index';

export default {
  namespace: 'index',

  state: {
    // 列表数据
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },
    dataqueryHomeCount: {
      dbList: [],
      leList: [],
      leTypeList: [],
      dbinfoTypeList: [],
      leWordeList: [],
    },
  },

  effects: {
    *queryList({ payload }, { call, put }) {
      const response = yield call(queryRoleList, payload);
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *queryHomeCount({ payload }, { call, put }) {
      const response = yield call(queryHomeCount, payload);
      yield put({
        type: 'savequeryHomeCount',
        payload: response.data || {
          dbList: [],
          leList: [],
          leTypeList: [],
          dbinfoTypeList: [],
          leWordeList: [],
        },
      });
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
    savequeryHomeCount(state, { payload }) {
      return {
        ...state,
        dataqueryHomeCount: payload,
      };
    },
  },
};
